﻿/* 2011/11/20 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Cosmos.Shortcuts;

namespace PictureManager
{
    public class KeyCombinationExecutant : ShortcutExecutant
    {
        public KeyCombinationExecutant(Keys key, bool control, bool alter, bool shift,
            PictureManagerOperationCategory operation, params string[] arguments)
            : base(new ShortcutOperation((int)operation, arguments), new KeyCombination(key, control, alter, shift))
        {

        }

        public KeyCombinationExecutant(Keys key, PictureManagerOperationCategory operation, params string[] arguments)
            : base(new ShortcutOperation((int)operation, arguments), new KeyCombination(key))
        {
        }

        public KeyCombinationExecutant(PictureManagerOperationCategory operation, params string[] arguments)
            : base(new ShortcutOperation((int)operation, arguments))
        {

        }

        public KeyCombinationExecutant(string escapeString)
            : base(escapeString)
        {

        }

        public bool Contains(KeyCombination keyCombination)
        {
            foreach (IShortcutAction anAction in _shortcutActions)
            {
                KeyCombination currentKeyCombination = (KeyCombination)anAction;
                if (currentKeyCombination.Equals(keyCombination))
                    return true;
            }
            return false;
        }

        public void Add(KeyCombination keyCombination)
        {
            if (_shortcutActions == null)
                _shortcutActions = new List<IShortcutAction>(1);

            _shortcutActions.Add(keyCombination);
        }

        public void Remove(KeyCombination keyCombination)
        {
            if (_shortcutActions != null)
                _shortcutActions.Remove(keyCombination);
        }

        public void RemoveAt(int index)
        {
            if (_shortcutActions != null)
                _shortcutActions.RemoveAt(index);
        }

        public void Clear()
        {
            if (_shortcutActions != null)
                _shortcutActions.Clear();
        }

        public KeyCombination this[int index]
        {
            get
            {
                if (ActionCount > 0 && index >= 0 && index < ActionCount)
                {
                    return (KeyCombination)_shortcutActions[index];
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
            set
            {
                if (ActionCount > 0 && index >= 0 && index < ActionCount)
                {
                    _shortcutActions[index] = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
        }

        public IEnumerable<KeyCombination> KeyCombinations
        {
            get
            {
                foreach (IShortcutAction anAction in _shortcutActions)
                {
                    yield return (KeyCombination)anAction;
                }
            }
        }
    }
}
